package com.ruoyi.project.game.tag.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.game.tag.domain.Tag;
import com.ruoyi.project.game.tag.service.ITagService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 游戏标签Controller
 * 
 * @author shixiangwen
 * @date 2020-02-11
 */
@Controller
@RequestMapping("/game/tag")
public class TagController extends BaseController
{
    private String prefix = "game/tag";

    @Autowired
    private ITagService tagService;

    @RequiresPermissions("game:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询游戏标签列表
     */
    @RequiresPermissions("game:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Tag tag)
    {
        startPage();
        List<Tag> list = tagService.selectTagList(tag);
        return getDataTable(list);
    }

    /**
     * 导出游戏标签列表
     */
    @RequiresPermissions("game:tag:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Tag tag)
    {
        List<Tag> list = tagService.selectTagList(tag);
        ExcelUtil<Tag> util = new ExcelUtil<Tag>(Tag.class);
        return util.exportExcel(list, "tag");
    }

    /**
     * 新增游戏标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存游戏标签
     */
    @RequiresPermissions("game:tag:add")
    @Log(title = "游戏标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Tag tag)
    {
        return toAjax(tagService.insertTag(tag));
    }

    /**
     * 修改游戏标签
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Tag tag = tagService.selectTagById(id);
        mmap.put("tag", tag);
        return prefix + "/edit";
    }

    /**
     * 修改保存游戏标签
     */
    @RequiresPermissions("game:tag:edit")
    @Log(title = "游戏标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Tag tag)
    {
        return toAjax(tagService.updateTag(tag));
    }

    /**
     * 删除游戏标签
     */
    @RequiresPermissions("game:tag:remove")
    @Log(title = "游戏标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tagService.deleteTagByIds(ids));
    }
}
